<?php
use Mirage\Abstraction\AbstractController;
use Mirage\Base\Renderer;
use Mirage\Web;
/**
 * Description of FrontController
 * Date Created Mar 14, 2012 5:34:30 PM
 * @package 
 * @author Bryan Salazar
 * 
 */
class FrontController extends AbstractController
{
//    /**
//     *
//     * @var \Mirage\Base\Renderer 
//     */
//    public $view;
    
    /**
     *
     * @var Twig_Environment 
     */
    public $view;
    
    public function init() 
    {
        $this->setupRenderer();
        
//        if(!isset(Web::app()->session['id']) && Web::app()->getModuleID() != 'front' && 
//                Web::app()->getControllerID() != 'site' && Web::app()->getActionID() != 'login') {
//        }
    }
    
    protected function setupRenderer()
    {
//        $this->view = new Renderer();
//        $viewPath = Web::app()->getModulePath().'/front/views';
//        $layoutPath = $viewPath . '/layouts';
//        $this->view->setLayoutPath($layoutPath);
//        $this->view->setViewPath($viewPath);
//        $this->view->layout = 'main';        
        
        require_once Web::app()->getBasePath() . '/vendor/Twig/lib/Twig/Autoloader.php';
        Twig_Autoloader::register();
        $modPath = Web::app()->getModulePath() . '/front';
        $templates = $modPath . '/views';
        $loader = new Twig_Loader_Filesystem($templates);
        $this->view = new Twig_Environment($loader, array(
            'cache' => $modPath . '/cache',
            'debug'=>false,
        ));
    }
    
    public function createUrl($url, $param=array()) {
        return Web::app()->createUrl('site/'.$url, $param);
    }
    
    public function redirect($url) {
        
        Web::app()->redirect($url);
    }
}
